package tichu_project252.Round;

import java.util.Collections;
import java.util.LinkedList;
import tichu_project252.CardClasses.Card;
import tichu_project252.Table;

public class Triple extends TurnType {

    /**
     * Returns true if the combination given is triple.
     *
     * <p> <b> Accessor(Selector): </b> isTriple(LinkedList <Card> l, Table t) </p>
     *
     * <p><b> Precondition: </b> The player should select some cards.</p> </p>
     * <p> <b> Postcondition:</b> Returns true if the combination is triple,
     * else it returns false. </p>
     *
     * @return if the combination is triple.
     */
    public static boolean isTriple(LinkedList<Card> l, Table t) {

        if (l.size() != 3) {  //if the cards aren't 3 we haven't got a triple
            return false;
        }

        if (hasPhoenix(l)) { //if there's a phoenix among the cards
            setPhoenix(l);
        }

        LinkedList<Integer> temp = new LinkedList<Integer>();//create a list to hold the intReprs of the cards

        for (int i = 0; i < l.size(); i++) {
            temp.add(l.get(i).getintRepr());    //add the intRepr of the cards into the linkedlist
        }
      
        Collections.sort(temp); //sort the cards
       
        temp = removeDuplicates(temp);  //remove duplicates
        
        //if there is only one int in the list after removing duplicates we have a triple
      
        if (temp.size() == 1) {
            //however if the selected cards are lower in value than the ones on the table return false
            if (t.getLastDropped().size() != 0) {
                if (temp.get(0) < t.getLastDropped().get(0).getintRepr()) {
                    return false;
                } else {
                    return true;
                }
            } else {
                return true;
            }
        } else {
            return false;
        }
    }

}
